<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>self Promise</title>
</head>
<body>
<script src="./js/Promise_class.js"></script>
<script>
    let p = new Promise((resolve,reject)=>{
        setTimeout(()=>{
            if(Date.now()%2===0){
                resolve(1);
            }else {
                reject(2);
            }
            console.log('promise 状态变了！');
        },100)

    });
    p.then(function onResolved(value){
        console.log('onResolved1()', value);
    }, function onRejected(reason){
        console.log('onRejected1()',reason);
    })
    p.then(function onResolved(value){
        console.log('onResolved2()', value);
    }, function onRejected(reason){
        console.log('onRejected2()',reason);
    })
    const p3 = Promise.resolve(3);
    const p4 = Promise.resolve(Promise.resolve(4));
    const p5 = Promise.resolve(Promise.reject(5));
    p3.then(value=>{
        console.log('p3', value)
    });
    p4.then(value=>{
        console.log('p4', value)
    });
    p5.catch(reason=>{
        console.log('p5', reason)
    });

    Promise.all([Promise.resolve(4),Promise.resolve(5),Promise.resolve(6)]).then(value=>{
        console.log(value)
    })
    Promise.race([Promise.resolve(4),Promise.resolve(5),Promise.resolve(6)]).then(value=>{
        console.log(value)
    })
    let delay1 = Promise.resolveDelay(66,3000);
    let delay2 = Promise.rejectDelay(77,3000);
    delay1.then(value=>{
        console.log(value)
    })
    delay2.then(()=>{},(reason)=>{
        console.log(reason);
    })
</script>
</body>
</html>